package com.lagou.edu.boss.rest;

import com.lagou.edu.ad.api.AdRemoteService;
import com.lagou.edu.ad.api.dto.PromotionAdDTO;
import com.lagou.edu.ad.api.dto.PromotionSpaceDTO;
import com.lagou.edu.common.result.ResponseDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author godai
 * @date 2021/8/24 22:10
 * @description
 */
@RestController
@RequestMapping("/ad")
public class AdController {

    @Autowired
    private AdRemoteService adRemoteService;

    @RequestMapping("/space/getAllSpaces")
    public ResponseDTO getAllSpace() throws Exception {
        List<PromotionSpaceDTO> dtoList = adRemoteService.getAllSpaces();
        return ResponseDTO.success(dtoList);
    }

    @PostMapping("/space/saveOrUpdate")
    public ResponseDTO saveOrUpdate(@RequestBody PromotionSpaceDTO spaceDTO) {
        return ResponseDTO.success(adRemoteService.saveOrUpdate(spaceDTO));
    }

    @GetMapping("/space/getSpaceById")
    public ResponseDTO getPromotionSpaceById(@RequestParam("id") Integer id) {
        return ResponseDTO.success(adRemoteService.getPromotionSpaceById(id));

    }

    @GetMapping("/getAdById")
    public ResponseDTO getAdById(@RequestParam("id") Integer id) {
        return ResponseDTO.success(adRemoteService.getAdById(id));
    }

    //获取所有的广告
    @GetMapping("/getAdList")
    public ResponseDTO getAdList() {
        return ResponseDTO.success(adRemoteService.getAdList());
    }

    @PostMapping("/saveOrUpdate")
    public ResponseDTO saveOrUpdateAd(@RequestBody PromotionAdDTO adDTO){
        return ResponseDTO.success(adRemoteService.saveOrUpdate(adDTO));
    }

}
